/**
 * 
 */
package com.zznode.client.wlanpolling.other;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.zznode.client.wlanpolling.R;
import com.zznode.client.wlanpolling.model.WebSiteManager;

/**
 * @author Pink
 *
 */
public class WebSiteAddActivity extends Activity {
	private EditText etWebSiteName;
	private EditText etWebSiteUrl;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.websiteadd);
		
		Button btnSaveWebSite = (Button)findViewById(R.id.btnSaveWebSite);
		
		etWebSiteName = (EditText)findViewById(R.id.edWebSiteName);
		etWebSiteUrl = (EditText)findViewById(R.id.edWebSiteUrl);
		
		btnSaveWebSite.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				saveWebSite();
			}
		});
	}
	
	private void saveWebSite() {
		//save
		String name = etWebSiteName.getText().toString();
		String url = etWebSiteUrl.getText().toString();
		
		if(name == null || name.length() ==0 
				|| url == null || url.length() == 0) {
			Toast.makeText(WebSiteAddActivity.this, "站点名/地址为空!", Toast.LENGTH_SHORT).show();
			return;
		}
		
		if(!url.toLowerCase().startsWith("http://")) {
			Toast.makeText(WebSiteAddActivity.this, "Url地址必须以http://开头", Toast.LENGTH_SHORT).show();
			return;
		}
		
		WebSiteManager.getWebSiteManager().addWebSite(name, url);
		finish();
	}
}
